/*  
 * Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved.
 */

package org.reliablesource.prism.ui.composite;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.reliablesource.prism.core.IPrismScreen;
import org.reliablesource.prism.ui.viewers.ImageViewer;

/**
 *
 *	ViewMediator.java<br>
 *	Created on: Mar 11, 2006<br><br>
 *
 *	@author Dennis Park 
 *		<a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 *	@since 1.0
 */

public class ViewMediator {

	private static ViewMediator instance;

	private static ImageViewer imageComposite;

	static {
		instance = new ViewMediator();
	}

	private ViewMediator() {
	}

	public static ViewMediator getInstance() {
		return instance;
	}

	public void registerPart(final Viewer comp) {
		if (comp instanceof ImageViewer)
			imageComposite = (ImageViewer) comp;
	}

	public void unregisterPart(final Composite comp) {
		if (comp instanceof ImageComposite)
			imageComposite = null;
	}

	public void openImage(final IPrismScreen screen) {
		if(imageComposite == null){
			try {
				PlatformUI.getWorkbench().getViewRegistry().find("org.reliablesource.prism.ui.workbench.views.imageview").createView();
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
		showNewImage(screen);
	}

	public void showNewImage(final IPrismScreen scr) {
			imageComposite.setSelection(new StructuredSelection(scr));
	}

	public void forward() {
			imageComposite.forward();
	}

	public void backward() {
			imageComposite.backward();
	}
}
